package org.bluedream.comm.base.bill;

import com.baomidou.mybatisplus.annotation.TableField;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.ToString;
import org.bluedream.comm.base.OrgPageEntity;
import org.bluedream.comm.base.PageEntity;
import org.bluedream.comm.utils.excel.ExcelType;
import org.bluedream.comm.utils.excel.FieldType;

import java.math.BigDecimal;

/**
 * @ClassName BillBodyEntity
 * @Description TODO
 * @Author foxsand
 * @Data 2021-11-09 11:25
 * @Version
 */
@Data
@ToString(callSuper = true)
@NoArgsConstructor
@EqualsAndHashCode(callSuper = false)
public class BillBodyEntity<T> extends OrgPageEntity<T> {
    private static final long serialVersionUID = 327846306674416617L;

    protected String billType;
    protected String billNum;
    protected String code;
    @FieldType(excelType = ExcelType.IMPORT , excelFieldName = "条码" , fieldSort = 0)
    protected String barcode;
    protected String name;
    @FieldType(excelType = ExcelType.IMPORT , excelFieldName = "数量" , fieldSort = 1)
    protected BigDecimal qty;
    @TableField(exist = false)
    protected String qtyStr;
    @TableField(exist = false)
    protected Integer qpc;
    @TableField(exist = false)
    protected String qpcStr;
    @TableField(exist = false)
    protected String unit;
    @TableField(exist = false)
    protected String spec;
    protected BigDecimal oprice;
    protected BigDecimal total;

    public void setQtyStr(){
        if (this.qty.compareTo(new BigDecimal("0")) == 0){
            throw new RuntimeException("OrdBody中的qty=0是非法的！");
        }

        if (this.qty.divide(BigDecimal.valueOf(this.qpc)).compareTo(new BigDecimal("0")) == 0){
            this.qtyStr = this.qty.divide(BigDecimal.valueOf(this.qpc)).toString();
        }else {
            Double temp = Math.floor(Double.valueOf(String.valueOf(this.qty.divide(BigDecimal.valueOf(this.qpc)))));
            this.qtyStr = temp == 0?temp + "+" + this.qty:temp + "+" + (this.qty.subtract(BigDecimal.valueOf(this.qpc)));
        }
    }

    public BillBodyEntity(String id){
        this.id = id;
    }

    public BillBodyEntity(long limit , long pageSize){
        super(limit , pageSize);
    }
}
